package com.test.main;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.engine.export.JRPdfExporter;
import net.sf.jasperreports.engine.util.AbstractSampleApp;
import net.sf.jasperreports.export.SimpleExporterInput;
import net.sf.jasperreports.export.SimpleOutputStreamExporterOutput;

public class GeneratePdf extends AbstractSampleApp
{

	public static void main(String[] args)
	{
		//main(new GeneratePdf(), args);
		try
		{
			new GeneratePdf().test();
		} catch (JRException e)
		{
			
			e.printStackTrace();
		}

	}

	@Override
	public void test() throws JRException
	{
		fill();
		//pdf();
		
	}

	public void fill() throws JRException
	{
		long start = System.currentTimeMillis();
		
		List<AttorneyAB> attorneyABLst = new ArrayList<AttorneyAB>();
		
		Map<String,Object> parameters = new HashMap<String,Object>();
//		parameters.put("projectName", "项目名称");
//		parameters.put("EngName1", "Mr.ZhangSan");
//		parameters.put("EngName2", "Ms.LiSi");
//		parameters.put("ChnName1", "张三先生");
//		parameters.put("ChnName2", "李四女士");

		parameters.put("code", "SC0116POA000001");
		parameters.put("uuid", "1234567890123456ABCDEFGHIJKLMNOP");
		
		AttorneyAB a = new AttorneyAB();
		a.setProjectName("海南金海浆纸业有限公司2C洗浆机所用之马达项目");
		a.setEngProjectName("JHPP MOTORS FOR 2C WASH PRESS Project");
		a.setChnName1("郭向阳 先生");
		a.setChnName2("吴文琰 女士");
		a.setEngName1("Mr. Guo Xiang Yang");
		a.setEngName2("Ms. Wu Wen Yan");
		a.setValidFromEn("July 07,2016");
		a.setValidToEn("Octomber 06,2016");
		a.setValidFromCn("2016年07月07日");
		a.setValidToCn("2016年10月06日");
		
		a.setEngPositionA("Sales Director Region South");
		a.setChnPositionA("华南区销售总监");
		a.setEngPositionB("Senior Commercial Officer");
		a.setChnPositionB("高级商务专员");
		
		
		a.setEngDeptA("FFI");
		a.setChnDeptA("森林与纤维行业部");
		a.setEngDivisionA("Large Drivers");
		a.setChnDivisionA("大型传动部");
		a.setEngBUA("Process Industries and Drivers");
		a.setChnBUA("过程工业与驱动集团");
		
		a.setEngDeptB("LD Projects BA");
		a.setChnDeptB("大型传动项目商务部");
		a.setEngDivisionB("Large Drivers");
		a.setChnDivisionB("大型传动部");
		a.setEngBUB("Process Industries and Drivers");
		a.setChnBUB("过程工业与驱动集团");
		
		
		a.setEngNegoType("excluding signing contract(s)");
		a.setChnNegoType("合同签署除外");
		
		//a.setDescription(");
		attorneyABLst.add(a);
		
		JasperPrint jp  = JasperFillManager.fillReport("D:\\viedo\\软件素材\\jasper\\report\\SLC_AB.jasper", parameters, new JRBeanCollectionDataSource(attorneyABLst));
		JasperExportManager.exportReportToPdfFile(jp,"D:\\viedo\\软件素材\\jasper\\report\\SLC_AB_excluding signing contract(s).pdf");
		jp  = JasperFillManager.fillReport("D:\\viedo\\软件素材\\jasper\\report\\SITL_AB.jasper", parameters, new JRBeanCollectionDataSource(attorneyABLst));
		JasperExportManager.exportReportToPdfFile(jp,"D:\\viedo\\软件素材\\jasper\\report\\SITL_AB_excluding signing contract(s).pdf");
		
		a.setEngNegoType("including signing contract(s)");
		a.setChnNegoType("含合同签署");
		jp  = JasperFillManager.fillReport("D:\\viedo\\软件素材\\jasper\\report\\SLC_AB.jasper", parameters, new JRBeanCollectionDataSource(attorneyABLst));
		JasperExportManager.exportReportToPdfFile(jp,"D:\\viedo\\软件素材\\jasper\\report\\SLC_AB_including signing contract(s).pdf");
		jp  = JasperFillManager.fillReport("D:\\viedo\\软件素材\\jasper\\report\\SITL_AB.jasper", parameters, new JRBeanCollectionDataSource(attorneyABLst));
		JasperExportManager.exportReportToPdfFile(jp,"D:\\viedo\\软件素材\\jasper\\report\\SITL_AB_including signing contract(s).pdf");
		
		System.err.println("Filling time : " + (System.currentTimeMillis() - start));
	}
	
	
	/**
	 *
	 */
	public void pdf() throws JRException
	{
		long start = System.currentTimeMillis();
		//JasperExportManager.exportReportToPdfFile("D:\\viedo\\svn_project\\workshop\\JasperDemo\\src\\test.jrprint");
		JRPdfExporter exporter = new JRPdfExporter();
		
		exporter.setExporterInput(new SimpleExporterInput("D:\\viedo\\软件素材\\jasper\\report\\SITL_AB.jrprint"));
		exporter.setExporterOutput(new SimpleOutputStreamExporterOutput("D:\\viedo\\软件素材\\jasper\\report\\SITL_AB.pdf"));
		
		exporter.exportReport();
		
		System.err.println("PDF creation time : " + (System.currentTimeMillis() - start));
	}
	
}
